<?php
/*
 * Created on Apr 27, 2009
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 class place_Form_EditPlace extends Zend_Form
 {
     protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );
    /**
     * init() is the initialization routine called when Zend_Form objects are 
     * created. In most cases, it make alot of sense to put definitions in this 
     * method, as you can see below.  This is not required, but suggested.  
     * There might exist other application scenarios where one might want to 
     * configure their form objects in a different way, those are best 
     * described in the manual:
     *
     * @see    http://framework.zend.com/manual/en/zend.form.html
     * @return void
     */ 
    public function cluBuild($params)
    {
        $filterHtmlBody = new Clu_Filter_HtmlBody();
        $filterTrim = new Zend_Filter_StringTrim();
        $filterFloat = new Zend_Validate_Float();
        $validatorNotEmpty = new Zend_Validate_NotEmpty();
        $myValidator = new Zend_Validate_Regex('/^[A-Z0-9_\s\.\-]*$/i'); //alpha, num, space, -, _
        $myValidator->setMessage(t(60), Zend_Validate_Regex::NOT_MATCH);
        // set the method for the display form to POST
        $this->setMethod('POST');
    	$this->setAction($params['action_url']);
		
 		if($params['category'] != 90)
 		{
	        //opening_hours
	        $opening_hours = new Zend_Form_Element_Text('opening_hours', array('disableLoadDefaultDecorators' => true,
	                                                                 'class' => 'inputText',
	                                                                 ));
	        $opening_hours->addDecorators($this->_noDecorator)
	                 	  /*->addValidator($filterFloat)*/;
	        $this->addElement($opening_hours);
	        
	        //belong_to
	        $belong_to = new Zend_Form_Element_Text('belong_to_ac_input', array('disableLoadDefaultDecorators' => true,
	                                                                 'class' => 'inputText',
	                                                                 ));
	        $belong_to->addDecorators($this->_noDecorator)
	        		  ->addFilter($filterTrim);
	        $this->addElement($belong_to);
	        
	        //belong_to_id
	        $belong_to = new Zend_Form_Element_Hidden('belong_to_ids', array('disableLoadDefaultDecorators' => true,
	                                                                 'class' => 'inputText',
	                                                                 ));
	        $belong_to->addDecorators($this->_noDecorator);
	        $this->addElement($belong_to);
	        
	        //belong_to_names_submit
	        $belong_to_names_submit = new Zend_Form_Element_Hidden('belong_to_names_submit', array('disableLoadDefaultDecorators' => true,
	                                                                 'class' => 'inputText',
	                                                                 ));
	        $belong_to_names_submit->addDecorators($this->_noDecorator);
	        $this->addElement($belong_to_names_submit);
	        
	        //distance
	        $distance = new Zend_Form_Element_Hidden('distance', array('disableLoadDefaultDecorators' => true,
	                                                                 'class' => 'inputText',
	                                                                 ));
	        $distance->addDecorators($this->_noDecorator);
	        $this->addElement($distance);
	        
	        //length
	        $length = new Zend_Form_Element_Text('length', array('disableLoadDefaultDecorators' => true,
	                                                                 'class' => 'inputText',
	                                                                 ));
	        $length->addDecorators($this->_noDecorator)
	                 ->addValidator($filterFloat);
	        $this->addElement($length);
	        
	        //fee :TODO
	        $fee = new Zend_Form_Element_Text('fee', array('disableLoadDefaultDecorators' => true,
	                                                                 'class' => 'inputText',
	                                                                 ));
	        $fee->addDecorators($this->_noDecorator)
	            ->addValidator($filterFloat);
	        $this->addElement($fee);
	        
	        //fee_basis
	        $fee_basis = new Zend_Form_Element_Select('fee_basis', array('disableLoadDefaultDecorators' => true,
	                                                                 'required' => true));
	        $fee_basis->addMultiOption('0','--'.t(97).'--')
	                  ->addMultiOption('entrance',t(733))
                      ->addMultiOption('hour',t(734))
                      ->addMultiOption('day',t(735))
                      ->addMultiOption('week',t(736))
                      ->addMultiOption('month',t(737))
	                  ->addDecorators($this->_noDecorator);
	        $this->addElement($fee_basis);
	        
	        
	        //fee_currency
	        $fee_currency = new Zend_Form_Element_Select('fee_currency', array('disableLoadDefaultDecorators' => true,
	                                                                 'required' => true));
	        $fee_currency->addMultiOption('0','--'.t(97).'--')
	                     ->addMultiOption('VND',__('VND'))
	                     ->addMultiOption('USD',__('USD'))
	                     ->addMultiOption('EURO',__('EURO'))
	                     ->addMultiOption('CNY',__('CNY'))
	                     ->addMultiOption('JPY',__('JPY'))
	                     ->addDecorators($this->_noDecorator);
	        $this->addElement($fee_currency);
	        
	        //payment_method
	       $payment_method = new Zend_Form_Element_MultiCheckbox('payment_method', array(
														    	'multiOptions' => array(
															        'cash' => t(798),
															        'creditcard' => t(799),
														   		 )
														));
	        $payment_method->addDecorators($this->_noDecorator);
	        $this->addElement($payment_method);
	    	// Hotel
	    	/*$hotel = Zend_Registry::get('configuration')->hotel;
			foreach ($hotel as $k => $h)*/
	    		if ($params['rtype'] == 3)  
				{
			    	// number_of_room
			        $number_of_room = new Zend_Form_Element_Text('number_of_rooms', 
			        												array('disableLoadDefaultDecorators' => true,
			                                                              'class' => 'inputText',
			                                                              ));
			        $number_of_room->addDecorators($this->_noDecorator)
			                  ->addValidator($myValidator);
			        $this->addElement($number_of_room);
		
			       // number_of_available_rooms
			       $number_of_available_rooms = new Zend_Form_Element_Text('number_of_available_rooms', 
				        												array('disableLoadDefaultDecorators' => true,
				                                                              'class' => 'inputText',
				                                                              ));
			        $number_of_available_rooms->addDecorators($this->_noDecorator)
			                  				  ->addValidator($myValidator);
			        $this->addElement($number_of_available_rooms);
	    		}	
	    	
		    //Restaurant
		    //$restaurant = Zend_Registry::get('configuration')->restaurant;
		    if($params['rtype'] == 2)
		    {
			    // take_away
			    $take_away = new Zend_Form_Element_Checkbox('take_away');
		       $take_away->setCheckedValue(true)
		       			 ->addDecorators($this->_noDecorator);
		       $this->addElement($take_away);
		       
		        // delivery
		        $delivery = new Zend_Form_Element_Checkbox('delivery');
		       $delivery->addDecorators($this->_noDecorator)
		                ->setCheckedValue(true);
		       $this->addElement($delivery);
	
		       //meals
		       $meals = new Zend_Form_Element_MultiCheckbox('meals', array(
														    'multiOptions' => array(
														        'morning' => 'Morning',
														        'noon' => 'Noon',
														        'evening' => 'Evening',
														        'night' => 'Night',
														    )
														));
		        $meals->addDecorators($this->_noDecorator);
		        $this->addElement($meals);
		    }
	       
	       // pagoda
	       //$pagoda = Zend_Registry::get('configuration')->pagoda;
	        if($params['rtype'] == 19)
	        {
	        	 // Built_Year
		        $built__year = new Zend_Form_Element_Text('built_year', array('disableLoadDefaultDecorators' => true,
		                                                                      'class' => 'inputText',
		                                                                      'required' => false));
		        $built__year->addDecorators($this->_noDecorator)
		                    ->addFilter($filterTrim)
		                  	/*->addValidator($myValidator)*/;
		        $this->addElement($built__year);
		        
		         // festive_days_from
		        $festive_days_from = new Zend_Form_Element_Text('festive_days_from', 
			        								   array('disableLoadDefaultDecorators' => true,
			                                                 'class' => 'inputText',
			                                           ));
		        $festive_days_from->addDecorators($this->_noDecorator)
		                  				  ->addValidator($myValidator);
		        $this->addElement($festive_days_from);
		       
		        // festive_days_to
		        $festive_days_to = new Zend_Form_Element_Text('festive_days_to', 
			        								   array('disableLoadDefaultDecorators' => true,
			                                                 'class' => 'inputText',
			                                           ));
		        $festive_days_to->addDecorators($this->_noDecorator)
		                  				  ->addValidator($myValidator);
		        $this->addElement($festive_days_to);
	        }
 		}
        //story body
        $fck = new Clu_Form_Element_FckEditor('article_body', array(
        		'fckOptions' => array (
        						'Height' => 600,
        						'Width'  => 630,
        						'ToolbarSet' => 'Full'
        					)
       			 )
        );
        $fck->setLabel(t(742));
        //$fck->addFilter($filterHtmlBody ); //TODO: if our people, maybe we don't need to filter
        
        $this->addElement($fck);
        
        // add an email element
        $contact_mail = new Zend_Form_Element_Text('contact_email', array('disableLoadDefaultDecorators' => true,
                                                                 'class' => 'inputText'
                                                                 ));
        $validatorEmail = new Zend_Validate_EmailAddress();
        $validatorEmail->setMessages(
            array(
                Zend_Validate_EmailAddress::INVALID            => t(743),
                Zend_Validate_EmailAddress::INVALID_HOSTNAME   => t(744),
        ));

        
        $contact_mail->addValidator($validatorNotEmpty, true)
                     ->addFilter($filterTrim)
              		 ->addValidator($validatorEmail)
              		 ->addDecorators($this->_noDecorator);
              
        $this->addElement($contact_mail);
        
        // add phone
        $phone = new Zend_Form_Element_Text('phone', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'inputText',
                                                                   'required' => false));
        $phone->addDecorators($this->_noDecorator)
                  ->addFilter($filterTrim)
                  ->addValidator($myValidator);
        $this->addElement($phone);
        
        // add fax
        $fax = new Zend_Form_Element_Text('fax', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'inputText',
                                                                   'required' => false));
        $fax->addDecorators($this->_noDecorator)
                  ->addFilter($filterTrim)
                  ->addValidator($myValidator);
        $this->addElement($fax);
        
        // Website
        $website = new Zend_Form_Element_Text('website', array('disableLoadDefaultDecorators' => true,
                                                               'class' => 'inputText',
                                                               'required' => false));
        $website->addDecorators($this->_noDecorator)
                  ->addFilter($filterTrim)
                  ->addValidator($myValidator);
        $this->addElement($website);
        
       
        
        // Area
        $area = new Zend_Form_Element_Text('area', array('disableLoadDefaultDecorators' => true,
                                                         'class' => 'inputText',
                                                         'required' => false));
        $area->addDecorators($this->_noDecorator)
                  ->addFilter($filterTrim)
                  ->addValidator($filterFloat)
                  ->addValidator($myValidator);
        $this->addElement($area);

    	
       //Update
        $update = new Zend_Form_Element_Submit('update', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(59) ));
	    $update->addDecorators($this->_noDecorator);
	    $this->addElement($update);
	    
	    // Category
 		$category = new Zend_Form_Element_Select('category',  
 											  array('disableLoadDefaultDecorators' => true,
									          ));
		$mCategory = new category_Model_Category();
		$mCategory->setTables('place');
        $category->addMultiOption('0','--'.t(113).'--');
        foreach ($mCategory->getRootType('Root_Place') as $c) {
        	//die(get_class($c));
        	$c = (array)$c;
        	if($c['id'] != 89)
        	{
	            $category->addMultiOption($c['id'], $c['name']);
	        	$category->addDecorators($this->_noDecorator);
        	}
        }
        $this->addElement($category);
        
        //rtype
        $rtype = new Zend_Form_Element_Select('rtype',  array('disableLoadDefaultDecorators' => true,
                                                                 'required' => false));
		$rtype->addMultiOption('0','--'.t(112).'--');                                                                 
		$rtype->setRegisterInArrayValidator(false)
			  ->addDecorators($this->_noDecorator);
        $this->addElement($rtype);
        
        //article originality
        $article_originality = new Zend_Form_Element_Select('article_originality',  
                         array('disableLoadDefaultDecorators' => true,
                                'required' => true)); 
        $article_originality->addMultiOption('copy',t(524))
        					->addMultiOption('collection',t(527))
                 			->addMultiOption('original',t(525))   
                 			->addDecorators($this->_noDecorator);
        $this->addElement($article_originality);
    }
 }
?>
